package com.wx.exam.controller;

import com.sun.org.apache.xpath.internal.operations.Bool;
import com.wx.exam.pojo.Dynamic;
import com.wx.exam.pojo.User;
import com.wx.exam.pojo.User_Dynamic;
import com.wx.exam.pojo.final_Dynamic;
import com.wx.exam.service.DynamicService;
import com.wx.exam.service.GatherService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author ychiha
 * @Date 2021/11/26 16:27
 * @Version 1.0
 */
@RestController
public class DynamicController {

    @Autowired
    private DynamicService dynamicService;

    @Autowired
    private GatherService gatherService;

    /**
     * 返回前端 动态 列表
     * @return
     */
    @RequestMapping("/dynamiclist")
    private List dynamiclist(){
        List<final_Dynamic> list = gatherService.getFinalDynamic();
        return list;
    }

    /**
     * 添加动态
     * @param
     * @return
     */
    @PostMapping("/adddynamic")
        private Boolean addDynamic(@RequestBody Dynamic dynamic){
        System.out.println("添加动态~********************:"+dynamic);
        if(dynamicService.addDynamic(dynamic)){
            User_Dynamic user_dynamic = new User_Dynamic();
            user_dynamic.setDid(dynamicService.getMaxDid());
            user_dynamic.setUid(dynamic.getUid());
            return dynamicService.addU_D(user_dynamic);
        }else{
            return false;
        }
    }

    /**
     * 添加用户id-动态id
     */
    @PostMapping("/addud")
    private Boolean addUD(@RequestBody User_Dynamic user_dynamic){
        System.out.println(user_dynamic);
        return dynamicService.addU_D(user_dynamic);
    }

    /**
     * 通过uid获取用户所有的Did
     * @param user
     * @return
     */
    @PostMapping("/getusersdynamic")
    private List<Integer> getDynamicByUid(@RequestBody User user){
        System.out.println(user);
        return dynamicService.getDynamicByUid(user);
    }

}
